/*
 * @lc app=leetcode.cn id=167 lang=javascript
 *
 * [167] 两数之和 II - 输入有序数组
 */

// @lc code=start
/**
 * @param {number[]} numbers
 * @param {number} target
 * @return {number[]}
 */
var twoSum = function (numbers, target) {
    //两指针分别从左右两端遍历
    let left = 0;
    let right = numbers.length - 1;
    while (left < right) {
        if (target - numbers[left] < numbers[right]) {
            right--;
        } else if (target - numbers[left] > numbers[right]) {
            left++
        } else {
            return [left + 1, right + 1]
        }
    }
};
// @lc code=end